<?php
class retrieve_editor extends retrieve_base{

	private $module_display_options 	= array();
	
	/**
    * Create Client Details
    *
    * This is the only function that allows the specification of the client_identifier as all other know this value
    * this function will load the database with what ever structure / content that is required on module initialisation for a
    * specific client it is called as part of the installation of a new client.
    */
    function create_client_details($parameters){
		$client_identifier = $this->check_parameters($parameters,"client_identifier",$this->client_identifier);
		$insert_new = $this->check_parameters($parameters,"insert_new_client",1);
		$data = array(
			Array('LOCALE_CMD_AUTO_FORMAT'			, 'auto_tidy'),
			Array('LOCALE_CUT_COPY_PASTE'			, 'cut_copy_paste'),
			Array('LOCALE_PASTE_SPECIAL'			, 'paste_special'),
			Array('LOCALE_UNDO_REDO'				, 'undo_redo'),
			Array('LOCALE_JUSTICICATION'			, 'justification'),
			Array('LOCALE_BOLD_ITALIC_UNDERLINE'	, 'bold_italic_underline'),
			Array('LOCALE_INTERNAL_LINK'			, 'internal_links'),
			Array('LOCALE_EXTERNAL_LINK'			, 'external_links'),
			Array('LOCALE_EMAIL_LINK'				, 'email_links'),
			Array('LOCALE_FILE_LINK'				, 'file_links'),
			Array('LOCALE_INSERT_IMAGES'			, 'images'),
			Array('LOCALE_INSERT_SPECIAL_CHARACTER'	, 'special_character'),
			Array('LOCALE_INSERT_HORIZONTAL_LINE'	, 'hr'),
			Array('LOCALE_DEFINE_HEADING'			, 'headings'),
			Array('LOCALE_CMD_CAN_TOGGLE_DESIGN'	, 'toggle_design'),
			Array('LOCALE_TIDY'						, 'tidy'),
			Array('LOCALE_INDENT_UNINDENT'			, 'indent_unindent'),
			Array('LOCALE_CAN_BULLET'				, 'bullet'),
			Array('LOCALE_CAN_EMBED_FORM'			, 'embed_form'),
			Array('LOCALE_TABLE_BASIC'				, 'tables_basic'),
			Array('LOCALE_TABLE_CELL'				, 'tables_cell'),
			Array('LOCALE_TABLE_ROW_COLUMN'			, 'tables_row_column'),
			Array('LOCALE_SET_ZOOM'					, 'set_zoom'),
			Array('LOCALE_ONLINE_HELP'				, 'help'),
			Array('LOCALE_PAGE_PROPERTIES'			, 'page_properties'),
			Array('LOCALE_ACRONYMS'					, 'abbr_acronym')
		);
		if (($this->parent->server[LICENCE_TYPE]==ECMS)||($this->parent->server[LICENCE_TYPE]==MECM)){
				$data[count($data)] = Array('LOCALE_DEFINE_SLIDESHOW'			, 'slideshow');

			if ($this->parent->server[LICENCE_TYPE]==ECMS){
				$data[count($data)] = Array('LOCALE_SPELL_CHECK'			, 'spell_checker');
				// neil requested move
				$data[count($data)] = Array('LOCALE_ACRONYMS_AND_ABBR'		, 'abbr_acronym');
				$data[count($data)] = Array('LOCALE_CAN_SET_FT'				, 'font_face');
				$data[count($data)] = Array('LOCALE_CMD_TABLE_CELL_COLOUR'	, 'tables_cell_colour');
				$data[count($data)] = Array('LOCALE_CMD_TABLE_COLOUR'		, 'tables_colour');
				$data[count($data)] = Array('LOCALE_CAN_SET_FS'				, 'font_size');
				$data[count($data)] = Array('LOCALE_CAN_SET_FC'				, 'fore_colour');
				$data[count($data)] = Array('LOCALE_CAN_SET_BG'				, 'background_colour');
				$data[count($data)] = Array('LOCALE_SUB_SUPER_STRIKE'		, 'sub_super_strike');
				$data[count($data)] = Array('LOCALE_CAN_EMBED_FLASH'		, 'embed_flash');
				$data[count($data)] = Array('LOCALE_CAN_EMBED_MOVIE'		, 'embed_movie');
				$data[count($data)] = Array('LOCALE_CAN_EMBED_AUDIO'		, 'embed_audio');
				$data[count($data)] = Array('LOCALE_FIND_REPLACE'			, 'find_replace');
				$data[count($data)] = Array('LOCALE_TABLE_CELL_SPLIT_MERGE'	, 'tables_split_merge');
//				$data[count($data)] = Array('LOCALE_CMD_CONTEXT_SENSITIVE_MENU', 'context_sensitive');
			}
		}
		if ($insert_new==1){
			for ($i=0;$i<count($data);$i++){
				$this->db->query("INSERT INTO editor_button ( editor_button_client, editor_button_label, editor_button_id) VALUES('".$client_identifier."', '".$data[$i][0]."', '".$data[$i][1]."');");
			}

			$now =$this->libertasGetDate("Y/m/d H:i:s");
			$sql = "INSERT INTO editor_config (editor_config_label, editor_config_client, editor_date_created, editor_created_by_user, editor_config_default) VALUES('Full Access', $client_identifier, '$now', '0', '1')";
			$result = $this->db->query($sql);
			$sql = "Select editor_config_identifier from editor_config where editor_config_label = 'Full Access' and editor_config_client = $client_identifier and editor_date_created =  '$now' and editor_created_by_user	= '0' and editor_config_default	= '1'";

			$result = $this->db->query($sql);
			$config=0;
			while($r 	= $this->db->fetch_array($result) ){
				$config=$r["editor_config_identifier"];
			}
			$sql = "select * from editor_button where editor_button_client = $client_identifier";
			$result = $this->db->query($sql);
			$index=0;
			while($r 	= $this->db->fetch_array($result) ){
				$sql = "INSERT INTO editor_settings (editor_setting_config, editor_setting_client, editor_setting_button) VALUES($config,$client_identifier,".$r["editor_button_identifier"].");";
				$this->db->query($sql);
			}
			$default = Array(
				"#ff0000","#00ff00",
				"#0000ff","#FFFF00",
				"#ff9900","#99cc99",
				"#99ff00","#ccffff",
				"#66cccc","#cc00ff",
				"#ff00cc","#993300"
				);
			for ($index=0;$index<count($default);$index++){
				$sql = "insert into editor_palette (editor_palette_client, editor_palette_colour) values ($this->client_identifier, '".$default[$index]."');";
				$this->db->query($sql);
			}
			$this->cache_editor($config);
		} else {
			$sql = "select distinct * from editor_button where editor_button_client = $this->client_identifier order by editor_button_id";
			$result = $this->db->query($sql);
			$searchlist = Array();
			while($r = $this->db->fetch_array($result)){
				$searchlist[count($searchlist)] = $r["editor_button_id"];
			}
			for ($i=0;$i<count($data);$i++){
				$found 		= 0;
				for ($s=0;$s<count($searchlist);$s++){
					if ($searchlist[$s] == $data[$i][1]){
						$found 		= 1;
					}
				}
				if ($found==0){
					$this->db->query("INSERT INTO editor_button ( editor_button_client, editor_button_label, editor_button_id) VALUES('".$client_identifier."', '".$data[$i][0]."', '".$data[$i][1]."')");
				}
			}
		}
	}

	/**
	* function produces abstract structure of modules db structure
	*
    * used to generate the table structure required abstract function that passes an abstract
	* representation of the desired table structure to the proper database module which will
	* interpet the abstract and convert it into a valid SQL Create table structure.
	*
	* @return Array list of abstract table definitions for this module
	*/
	function create_table(){
		$tables = array();

		/**
		*Table structure for table 'editor_config'
		*/

		$fields = array(
			array("editor_config_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("editor_config_label"			,"varchar(255)"				,"NOT NULL"	,"default '0'"),
			array("editor_config_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_date_created"			,"datetime"					,"NOT NULL"	,"default ''"),
			array("editor_created_by_user"		,"unsigned integer"			,"NOT NULL"	,"default '0'","key"),
			array("editor_config_default"		,"unsigned small integer"	,"NOT NULL"	,"default '0'","")
		);

		$primary ="editor_config_identifier";
		$tables[count($tables)] = array("editor_config", $fields, $primary);

		/**
		*Table structure for table 'editor_settings'
		*/

		$fields = array(
			array("editor_setting_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("editor_setting_config"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_setting_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_setting_button"		,"unsigned integer"			,"NOT NULL"	,"default '0'")
		);

		$primary ="editor_setting_identifier";
		$tables[count($tables)] = array("editor_settings", $fields, $primary);


		/**
		*Table structure for table 'editor_belongs_to_group'
		*/

		$fields = array(
			array("editor_belongs_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("editor_belongs_config"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_belongs_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_belongs_group"		,"unsigned integer"			,"NOT NULL"	,"default '0'")
		);

		$primary ="editor_belongs_identifier";
		$tables[count($tables)] = array("editor_belonging_to_group", $fields, $primary);

		/**
		*Table structure for table 'editor_buttons'
		*/

		$fields = array(
			array("editor_button_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("editor_button_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_button_label"			,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("editor_button_id"			,"varchar(255)"				,"NOT NULL"	,"default ''")
		);

		$primary ="editor_button_identifier";
		$tables[count($tables)] = array("editor_button", $fields, $primary);
		/**
		*Table structure for table 'editor_buttons'
		*/

		$fields = array(
			array("editor_palette_identifier"	,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("editor_palette_client"		,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("editor_palette_colour"		,"varchar(255)"				,"NOT NULL"	,"default ''")
		);

		$primary ="editor_palette_identifier";
		$tables[count($tables)] = array("editor_palette", $fields, $primary);

		/**
		*Table structure for table 'editor_buttons'
		*/

		$fields = array(
			array("mate_identifier"		,"unsigned integer"			,"NOT NULL"	,"auto_increment","key"),
			array("mate_client"			,"unsigned integer"			,"NOT NULL"	,"default '0'"),
			array("mate_name"			,"varchar(255)"				,"NOT NULL"	,"default ''"),
			array("mate_configuration"	,"unsigned integer"				,"NOT NULL"	,"default ''"),
			array("mate_status"			,"unsigned integer"				,"NOT NULL"	,"default ''"),
			array("mate_module"			,"varchar(50)"				,"NOT NULL"	,"default ''")
		);

		$primary ="mate_identifier";
		$tables[count($tables)] = array("module_access_to_editor", $fields, $primary);


		return $tables;
	}

    /**
    * Cache Editor
    *
    * This function will cache the editor definition to the hard disk to remove the need to check the database for details
    *
    * @param Integer the identifier of the record to be cached
    */

	function cache_editor($identifier){
		$out = $this->generate_editor_config(Array("identifier" => $identifier,"display"=>"none"));
		$lang="en";
		$data_files = $this->parent->site_directories["DATA_FILES_DIR"];
		$fp = fopen($data_files."/editor_".$this->client_identifier."_".$lang."_".$identifier.".xml", 'w');
		fwrite($fp, $out);
		fclose($fp);
	    $um = umask(0);
		@chmod($data_files."/editor_".$this->client_identifier."_".$lang."_".$identifier.".xml", LS__FILE_PERMISSION);
		umask($um);
	}

    /**
    * Generate Editor Configuration
    *
    * This function will build the data fro the cache function
    *
    * @param Array requiring the following keys to be defined ("identifier", "display")
	* @return String representing the xml structure for this configuration
    */

    function generate_editor_config($parameters){
		$out		= "";
        $left       = "";
        $right      = "";
		$label		= "";
        $btn_list= Array();

		$identifier = $this->check_parameters($parameters,"identifier");
		$display 	= $this->check_parameters($parameters,"display");
		$sql 		="select * from editor_settings
						inner join editor_button on editor_button.editor_button_identifier = editor_settings.editor_setting_button
						inner join editor_config on editor_config.editor_config_identifier = editor_settings.editor_setting_config
					  where editor_setting_config =$identifier and editor_setting_client=$this->client_identifier";
//		print "<p>".$sql."</p>";
		if($result = $this->db->query($sql)) {
			while($r = $this->db->fetch_array($result)){
				$label = $r["editor_config_label"];
				$out .="<btn id='".$r["editor_button_id"]."'><![CDATA[".$r["editor_button_label"]."]]></btn>";
                $btn_list[count($btn_list)] = $r["editor_button_id"];
			}
			$this->db->free_result($result);
		}
        $top        = "";
        $browser    = "";
        $version    = 0;
        if (1==2){
            $browser = "IE" ;
            $version = 6;
        }
		if (in_array('auto_tidy', $btn_list)){
			$top .= "<img id='LIBERTAS_[[editor]]_tb_auto_tidy' name='LIBERTAS_[[editor]]_tb_auto_tidy' src='/libertas_images/themes/1x1.gif' width='1' height='1' alt='Auto tidy'/>";
		}
		if (in_array('tables_cell_colour', $btn_list)){
			$top .= "<img id='LIBERTAS_[[editor]]_tb_tables_cell_colour' name='LIBERTAS_[[editor]]_tb_tables_cell_colour' src='/libertas_images/themes/1x1.gif' width='1' height='1' alt='Table Cell Colour'/>";
		}
		if (in_array('tables_colour', $btn_list)){
			$top .= "<img id='LIBERTAS_[[editor]]_tb_tables_colour' name='LIBERTAS_[[editor]]_tb_tables_colour' src='/libertas_images/themes/1x1.gif' width='1' height='1' alt='Table Colour'/>";
		}
		if (in_array('toggle_design', $btn_list)){
			$top .= "<img id='LIBERTAS_[[editor]]_tb_toggle_design' name='LIBERTAS_[[editor]]_tb_toggle_design' src='/libertas_images/themes/1x1.gif' width='1' height='1' alt='Can toggle design'/>";
		}
		
        //$m      = count($btn_list);
        //for($i=0; $i< $m ;$i++){
            if (in_array('cut_copy_paste', $btn_list)){
            	$top .= $this->gen_button('tb_cut','Cut','LIBERTAS_on_click','Cut');
            	$top .= $this->gen_button('tb_copy','Copy','LIBERTAS_on_click','Copy');
            	if ($this->parent->server[LICENCE_TYPE]==SITE_WIZARD) {
            		$top .= $this->gen_button('tb_paste_special','Paste Special','LIBERTAS_paste_special_click','paste_special');
            	} else {
            		if ($this->parent->server[LICENCE_TYPE]==ECMS) {
            			if (!in_array('auto_tidy', $btn_list)){
            				$top .= $this->gen_button('tb_paste','Paste','LIBERTAS_on_click','Paste');
            			} else {
            				$top .= $this->gen_button('tb_paste_special','Paste Special','LIBERTAS_paste_special_click','paste_special');
            			}
            		} else {
            			$top .= $this->gen_button('tb_paste_special','Paste Special','LIBERTAS_paste_special_click','paste_special');
            		}
            		if (in_array('paste_special', $btn_list)){
            			$top .= $this->gen_button('tb_dropdown','Paste As...','LIBERTAS_dropdown_menu_click','paste');
            		}
            	}
            }
            if (in_array('tidy', $btn_list)){
            	$top .= $this->gen_button('tb_vertical_separator','','');
            	$top .= $this->gen_button('tb_cleanup','HTML cleanup (removes styles, spans and fonts)','LIBERTAS_cleanup_click');
            }
            if (in_array('paste_special', $btn_list) || in_array('cut_copy_paste', $btn_list) || in_array('tidy', $btn_list)){
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('undo_redo', $btn_list)){
            	$top .= $this->gen_button('tb_undo','Undo','LIBERTAS_on_click','Undo');
            	$top .= $this->gen_button('tb_redo','Redo','LIBERTAS_on_click','Redo');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('find_replace', $btn_list)){
            	$top .= $this->gen_button('tb_find', 'Find', 'LIBERTAS_find_click');
            	$top .= $this->gen_button('tb_replace', 'Replace', 'LIBERTAS_replace_click');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('internal_links', $btn_list)){
            	$top .= $this->gen_button('tb_hyperlink','Internal Hyperlink','LIBERTAS_hyperlink_click', 'hyper');
            }
            if (in_array('external_links', $btn_list)){
            	$top .= $this->gen_button('tb_externallink','External Hyperlink','LIBERTAS_hyperlink_click', 'external');
            }
            if (in_array('email_links', $btn_list)){
            	$top .= $this->gen_button('tb_emaillink','Email Address Link','LIBERTAS_hyperlink_click', 'email');
            }
            if (in_array('file_links', $btn_list)){
            	$top .= $this->gen_button('tb_filelink','Link to a file','LIBERTAS_hyperlink_click', 'file');
            }
            if (in_array('internal_links', $btn_list) || in_array('external_links', $btn_list) || in_array('email_links', $btn_list) || in_array('file_links', $btn_list)){
            	$top .= $this->gen_button('tb_unlink','Remove Hyperlink','LIBERTAS_unlink_click');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('emocs_icons', $btn_list)){
            	$top .= $this->gen_button('tb_emoc','Insert Emocs Icon','LIBERTAS_emocs_click');
            }
            if (in_array('embed_flash', $btn_list)){
            	$top .= $this->gen_button('tb_flash', 'Insert Flash Object', 'LIBERTAS_flash_click');
            }
            if (in_array('embed_movie', $btn_list)){
            	$top .= $this->gen_button('tb_movie', 'Insert Movie', 'LIBERTAS_movie_click');
            }
            if (in_array('embed_audio', $btn_list)){
            	$top .= $this->gen_button('tb_audio', 'Insert Audio', 'LIBERTAS_audio_click');
            }
            if (in_array('images', $btn_list)){
            	$top .= $this->gen_button('tb_image_insert','Insert Image','LIBERTAS_image_insert_click');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('sub_super_strike', $btn_list)){
            	$top .= $this->gen_button('tb_subscript', 'SubScript', 'LIBERTAS_on_click','Subscript');
            	$top .= $this->gen_button('tb_superscript', 'SuperScript', 'LIBERTAS_on_click','Superscript');
            	$top .= $this->gen_button('tb_strikethrough', 'Strike Through', 'LIBERTAS_on_click','strikethrough');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('hr', $btn_list)){
            	$top .= $this->gen_button('tb_hr','Horizontal Rule','LIBERTAS_on_click','inserthorizontalrule');
            }
            if (in_array('special_character', $btn_list)){
            	$top .= $this->gen_button('tb_special_character','Insert Special Characters','LIBERTAS_special_char_click');
            	$top .= $this->gen_button('tb_dropdown','Special Character Lookup','LIBERTAS_dropdown_menu_click','html_entity');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('embed_form', $btn_list)){
            	$top .= $this->gen_button('tb_form', 'Embed a web form', 'LIBERTAS_embed_form_click');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('embed_audio', $btn_list) || in_array('embed_movie', $btn_list) || in_array('embed_flash', $btn_list)){
            }

            if (in_array('spell_checker', $btn_list)){
            	$top .= $this->gen_button('tb_spell', 'Check Spelling', 'LIBERTAS_spell_click');
            }
            if (in_array('page_properties', $btn_list)){
            	$top .= $this->gen_button('tb_page_prop', 'Page Statictics', 'LIBERTAS_stats_click');
            }
            if (in_array('spell_checker', $btn_list) || in_array('page_properties', $btn_list)){
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            $top .= $this->gen_button('tb_acronym','Acronym','LIBERTAS_acronym');
            //			$top .= $this->gen_button('tb_abbr','Abbreviation','LIBERTAS_abbr');
            $top .= $this->gen_button('tb_vertical_separator','','');
            $top .= $this->gen_button('tb_help','Online Help','LIBERTAS_help_click');
            $top .= $this->gen_button( 'endRow', '', '');
            $top .= $this->gen_button( 'startRow', '', '');
            if ($this->parent->server[LICENCE_TYPE]==ECMS) {
            	if (in_array('set_zoom', $btn_list)){
            		if ($browser == "IE" && $version>=5.5){
            			// this function requires IE 5.5 and Above
            			$top .= $this->gen_button('set_zoom','','');
            		}
            	}
            }
            if (in_array('headings', $btn_list)){
            	$top .= $this->gen_button('select_paragraph','','');
            }
            if (in_array('font_face', $btn_list)){
            	$top .= $this->gen_button('select_font_face','','');
            }
            if (in_array('font_size', $btn_list)){
            	$top .= $this->gen_button('select_font_size','','');
            }
            if (in_array('font_face', $btn_list) || in_array('font_size', $btn_list)){
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('bold_italic_underline', $btn_list)){
            	$top .= $this->gen_button('tb_bold','Bold','LIBERTAS_on_click','Bold');
            	$top .= $this->gen_button('tb_italic','Italic','LIBERTAS_on_click','Italic');
            	$top .= $this->gen_button('tb_underline','Underline','LIBERTAS_on_click','Underline');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('justification', $btn_list)){
            	$top .= $this->gen_button('tb_left','Left','LIBERTAS_on_click','justifyleft');
            	$top .= $this->gen_button('tb_center','Center','LIBERTAS_on_click','justifycenter');
            	$top .= $this->gen_button('tb_right','Right','LIBERTAS_on_click','justifyright');
            	$top .= $this->gen_button('tb_justify','Justify','LIBERTAS_justify_click');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('indent_unindent', $btn_list)){
            	$top .= $this->gen_button('tb_indent','Indent','LIBERTAS_on_click','Indent');
            	$top .= $this->gen_button('tb_unindent','Unindent','LIBERTAS_on_click','Outdent');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('bullet', $btn_list)){
            	$top .= $this->gen_button('tb_ordered_list','Ordered List','LIBERTAS_on_click','InsertOrderedList');
            	$top .= $this->gen_button('tb_bulleted_list','Bulleted List','LIBERTAS_on_click','InsertUnorderedList');
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('fore_colour', $btn_list)){
            	$top .= $this->gen_button('tb_fore_color', 'Set fore color', 'LIBERTAS_fore_color_click');
            	$top .= $this->gen_button('tb_dropdown','Select Color...','LIBERTAS_dropdown_menu_click','color_fore');
            }
            if (in_array('background_colour', $btn_list)){
            	$top .= $this->gen_button('tb_bg_color', 'Set background color', 'LIBERTAS_bg_color_click');
            	$top .= $this->gen_button('tb_dropdown','Select Color...','LIBERTAS_dropdown_menu_click','color_bg');
            }
            if (in_array('background', $btn_list) || in_array('fore_colour', $btn_list)){
            	$top .= $this->gen_button('tb_vertical_separator','','');
            }
            if (in_array('slideshow', $btn_list)){
            	$top .= $this->gen_button('tb_slideshow','Slideshow','LIBERTAS_embed_slideshow_click','undefined');
            }
        //}
            if (in_array('tables_basic', $btn_list) || in_array('tables_cell', $btn_list) || in_array('tables_row_column', $btn_list)  || in_array('tables_split_merge', $btn_list)){
                $left .= $this->gen_button('tb_table_create','Create a new table','LIBERTAS_table_create_click');
            	$left .= $this->gen_button('tb_dropdown','Table Wizard','LIBERTAS_dropdown_menu_click','tableWizard')."<br />";
            	$left .= $this->gen_button('tb_table_prop','Table properties','LIBERTAS_table_prop_click')."<br />";
            }
            if (in_array('tables_cell', $btn_list) && ($this->parent->server[LICENCE_TYPE]!=SITE_WIZARD)){
            	$left .= $this->gen_button('tb_table_cell_prop','Table Cell properties','LIBERTAS_table_cell_prop_click')."<br />";
            }
            if (in_array('tables_row_column', $btn_list)){
            	$left .= $this->gen_button('tb_table_row_insert','Insert a row into this table','LIBERTAS_table_row_insert_click')."<br />";
            	$left .= $this->gen_button('tb_table_column_insert','Insert a column into this table','LIBERTAS_table_column_insert_click')."<br />";
            	$left .= $this->gen_button('tb_table_row_delete','Table Row Delete','LIBERTAS_table_row_delete_click')."<br />";
            	$left .= $this->gen_button('tb_table_column_delete','Delete a column for this table ','LIBERTAS_table_column_delete_click')."<br />";
            }
            if (in_array('tables_split_merge', $btn_list)){
            	$left .= $this->gen_button('tb_table_cell_merge_right', 'Merge table cell right', 'LIBERTAS_table_cell_merge_right_click')."<br />";
            	$left .= $this->gen_button('tb_table_cell_merge_down', 'Merge table cell down', 'LIBERTAS_table_cell_merge_down_click')."<br />";
            	$left .= $this->gen_button('tb_table_cell_split_horizontal', 'Split table cell horizontally', 'LIBERTAS_table_cell_split_horizontal_click')."<br />";
            	$left .= $this->gen_button('tb_table_cell_split_vertical', 'Split table cell vertically', 'LIBERTAS_table_cell_split_vertical_click')."<br />";
            }
            if (in_array('tables_basic', $btn_list)){
            	$left .= $this->gen_button('tb_toggle_borders','Toggle table borders','LIBERTAS_toggle_borders_click')."<br />";
            }
        $return_data ="";
		if ($display!="none"){
			$return_data = "<module name='".$this->module_name."' display='settings'>";
		}
        $top = htmlentities(htmlentities($top));
        $left = htmlentities(htmlentities($left));
        $out .= "<top><![CDATA[$top]]></top>";
		$out .= "<left><![CDATA[$left]]></left>";
		$return_data .= "<setting id='".$identifier."' name='".$label."'>$out</setting>";
		if ($display!="none"){
			$return_data .= "</module>";
		}
		return $return_data;
	}
    /**
    * @access private;
    * generate a button for the editor
    * @param string the icon to use
    * @param string the mouseover label text for the button
    * @param string the Javascript function to call
    * @param string extra parameters required???
	*
	* @return String returns a string containing a HTML IMG tag with all required settings set
    */
    function gen_button($img,$alt,$fn,$exParam =""){
        $editor ="[[editor]]";
        $out="";
        if ($img=='startRow'){
            $out .="";
    	} else if ($img=='endRow'){
            $out .="<br />";
    	} else if ($img=='tb_vertical_separator') {
    		$out .="<img alt='' src='/libertas_images/editor/libertas/lib/themes/default/img/tb_vertical_separator.gif' width='3' height='24'/>";
    	} else if ($img=='select_paragraph') {
    		$out .= "<select id='chooseHeading' onChange=\"LIBERTAS_change_paragraph_click('[[editor]]', this);\" style='width:100px;font-size:0.8em;margin-bottom:5px'>";
    		$out .= "<option value='P'>Headings</option>";
    		$out .= "<option value='P'>Normal</option>";
            for($i=1; $i<7;$i++){
            	    $out.="<option value='H".$i."'>Heading $i</option>";
            }
    		$out .= "</select>";
    	} else if ($img=='select_font_face') {
    		$out .= "<select id='chooseFont' onChange=\"LIBERTAS_set_font_face('[[editor]]', this);\" style='width:100px;font-size:0.8em;margin-bottom:5px'>";
  			$fonts = Array(
                Array("Font name",		""),
                Array("Default", 		""),
    		    Array("Times Roman",	"Times Roman"),
    		    Array("Arial", 		    "Arial"),
    		    Array("Arial Black",	"Arial Black"),
    		    Array("Arial Narrow",	"Arial Narrow"),
    		    Array("Georgia", 		"Georgia"),
    		    Array("Terminal", 		"Terminal"),
    		    Array("Verdana", 		"Verdana")
            );
            for($i=1; $i<count($fonts);$i++){
                $out.="<option value='".$fonts[$i][1]."'>".$fonts[$i][0]."</option>";
            }
    		$out .= "</select>";
        } else if ($img=='select_font_size') {
            $out .= "<select id='chooseFontSize' onChange=\"LIBERTAS_set_font_size('[[editor]]', this);\" style='width:100px;font-size:0.8em;margin-bottom:5px'>";
  			$fonts = Array(
			    Array("Font Size",		""),
    		    Array("Default",		"3"),
    		    Array("x-small",		"1"),
    		    Array("small",			"2"),
    		    Array("normal",			"3"),
    		    Array("big",			"4"),
                Array("bigger",			"5"),
    		    Array("large",			"6"),
    		    Array("x-large",		"7")
            );
            for($i=1; $i<count($fonts);$i++){
                $out.="<option value='".$fonts[$i][1]."'>".$fonts[$i][0]."</option>";
            }
    		$out .= "</select>";
        } else if ($img=='set_zoom') {
            $size = Array(
                Array("Zoom",		""),
    			Array("Default",	"100"),
    			Array("75%",		"75"),
    			Array("100%",		"100"),
    			Array("125%",		"125"),
    			Array("150%",		"150"),
    			Array("200%",		"200"),
    			Array("300%",		"300")
            );
            $out .= "<select id='chooseZoom' onChange=\"LIBERTAS_setZoom('[[editor]]', this);\" style='width:100px;font-size:0.8em;margin-bottom:5px'>";
            for($i=1; $i<count($size);$i++){
                $out.="<option value='".$size[$i][1]."'>".$size[$i][0]."</option>";
            }
    		$out .= "</select>";
        } else {
            if ($exParam.''!=''){
    			$exParam = ",'".$exParam."'";
    		} else {
    			$exParam ='';
    		}
    		if ($img=='tb_dropdown'){
    			$image_width = 11;
    		} else {
    			$image_width = 24;
    		}
        	$out .= "<img class='LIBERTAS_default_tb_out' unselectable='on' id='LIBERTAS_".$editor."_".$img."' name='LIBERTAS_".$editor."_".$img."' alt='".$alt."' vspace='3' src='/libertas_images/editor/libertas/lib/themes/default/img/".$img.".gif' width='".$image_width."' height='24' onclick=\"".$fn."('".$editor."',this ". $exParam .")\" onmouseover='LIBERTAS_default_bt_over(this);' onmouseout='LIBERTAS_default_bt_out(this);' onmousedown='LIBERTAS_default_bt_down(this);' onmouseup='LIBERTAS_default_bt_up(this);'>";
    	}
        return $out;
    }

}
?>